class aa {
    name;
}
const App = {
    extends: Parent,
    methods: {
        init() {
            this.selectMyUser();

            //获取个人动态
            this.selectMyTrends();
            //查询收藏动态
            this.selectCollectTrends();
            //查询草稿动态
            this.selectSaveTrends();

            //查询个人社区
            this.selectMyCommunity();
            //查询关注社区
            this.selectCommunityMember();
        },
        selectMyTrends() {
            var _this = this;
            axios({
                method:"get",
                url:ParentUrl+"/Trends/3",
            }).then(resp => {
                _this.Result = resp.data;
                if(_this.Result.code === 1) {
                    _this.trends = _this.Result.data;
                } else {
                }
            })
        },//查询个人动态
        selectCollectTrends() {
            var _this = this;
            axios({
                method:"get",
                url:ParentUrl+"/Trends/6",
            }).then(resp => {
                _this.Result = resp.data;
                if(_this.Result.code === 1) {
                    _this.collectTrends = _this.Result.data;
                } else {

                }
            })
        },//查询收藏动态
        selectSaveTrends() {
            var _this = this;
            axios({
                method:"get",
                url:ParentUrl+"/Trends/10",
            }).then(resp => {
                _this.Result = resp.data;
                if(_this.Result.code === 1) {
                    _this.saveTrends = _this.Result.data;
                } else {

                }
            })
        },//查询草稿动态
        //查询评论
        selectCritique(trendsId) {
            var _this = this;
            axios.get(ParentUrl+"/Critique/"+trendsId).then(resp=>{
                _this.Result = resp.data;
                if(_this.Result.code===1) {
                    _this.critiques = _this.Result.data;
                }
                else {
                    _this.critiques = null;
                }
            });
        },
        //删除个人动态
        deleteMyTrends(id) {
            this.$confirm('删除后将不可找回，确认删除该条动态吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                var _this = this;
                axios.delete(ParentUrl+"/Trends/"+id).then(resp=>{
                    _this.Result = resp.data;
                    if(_this.Result.code === 1) {
                        this.$message({
                            message: '动态删除成功！',
                            type: 'success'
                        });
                    } else {

                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        addCommunityMember(communityId) {
            axios.post(ParentUrl+"/CommunityMember/"+communityId).then(resp=>{
                this.Result = resp.data;
                if(this.Result.code === 1) {
                    this.$message({
                        message: '成功加入！',
                        type: 'success'
                    });
                } else {
                    this.$message({
                        message: '加入失败！',
                        type: 'warning'
                    });
                }
            });
        },//加入社区成员
        //查询社区
        selectCommunity(name) {
            var _this = this;
            axios.get(ParentUrl+"/Community/"+name).then(resp=>{
                _this.Result = resp.data;
                if(_this.Result.code===1) {
                    _this.hCommunity = _this.Result.data;
                }
                else {
                }
            });
        },
        //点赞
        like(trend) {
            var _this = this;
            axios.put(ParentUrl+"/Trends/1/"+trend.id).then(resp=>{
                _this.Result = resp.data;
                //成功点赞
                if (_this.Result.code===1) {
                    this.$message({
                        message: '点赞成功！',
                        type: 'success'
                    });
                    trend.likesNum++;
                }
                //取消点赞
                else if (_this.Result.code===-1) {
                    this.$message({
                        message: '已取消点赞。',
                        type: 'success'
                    });
                    trend.likesNum--;
                }
                //点赞失败
                else {
                    this.$message({
                        message: '点赞失败！',
                        type: 'warning'
                    });
                }
            });
        },
        //收藏
        collect(trend) {
            var _this = this;
            axios.put(ParentUrl+"/Trends/2/"+trend.id).then(resp=>{
                _this.Result = resp.data;
                //成功点赞
                if (_this.Result.code===1) {
                    this.$message({
                        message: '收藏成功！',
                        type: 'success'
                    });
                    trend.collectNum++;
                }
                //取消点赞
                else if (_this.Result.code===-1) {
                    this.$message({
                        message: '已取消收藏。',
                        type: 'success'
                    });
                    trend.collectNum--;
                }
                //点赞失败
                else {
                    this.$message({
                        message: '收藏失败！',
                        type: 'warning'
                    });
                }
            });
        },
        //评论
        critiqueTrends() {
            var _this = this;
            axios.post(ParentUrl+"/Critique", _this.critique).then(resp=>{
                _this.Result = resp.data;
                if(_this.Result.code===1) {
                    _this.critiques=null;
                    _this.critiqueDialog = false;
                    this.$message({
                        showClose: true,
                        message: '评论成功！',
                        type: 'success'
                    });
                } else {
                    this.$message({
                        showClose: true,
                        message: '评论失败！',
                        type: 'warning'
                    });
                }
            })
        },
        deleteMyCommunity(id) {
            this.$confirm('删除后所有数据将不可找回，确认删除该社区吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                var _this = this;
                axios.delete(ParentUrl+"/Community/"+id).then(resp=>{
                    _this.Result = resp.data;
                    if(_this.Result.code === 1) {
                        this.$message({
                            message: '社区删除成功！',
                            type: 'success'
                        });
                        _this.selectMyCommunity();
                    } else {
                        this.$message({
                            type: 'info',
                            message: '社区删除失败！'
                        });
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },//删除个人社区
        //查询个人社区
        selectMyCommunity() {
            axios.get(ParentUrl+"/Community/1").then(resp=>{
                this.Result = resp.data;
                if(this.Result.code === 1) {
                    this.myCommunities = this.Result.data;
                } else {

                }
            });
        },
        //查询关注社区
        selectCommunityMember() {
            axios.get(ParentUrl+"/Community/2").then(resp=>{
                this.Result = resp.data;
                if(this.Result.code === 1) {
                    this.memberCommunities = this.Result.data;
                } else {

                }
            });
        },
        searchTrendsByCommunity(name) {
            var _this = this;
            axios({
                method:"get",
                url:ParentUrl+"/Trends/5?name="+name
            }).then(resp => {
                _this.Result = resp.data;
                if(_this.Result.code === 1) {
                    _this.communityTrends = _this.Result.data;
                    _this.communityTrendsDialog=true;
                } else {

                }
            })
        },//查询社区动态
        quitCommunityMember(communityId) {
            axios.delete(ParentUrl+"/CommunityMember/"+communityId).then(resp=>{
                this.Result = resp.data;
                if(this.Result.code === 1) {
                    this.$message({
                        message: '成功退出！',
                        type: 'success'
                    });
                } else {
                    this.$message({
                        message: '退出失败！',
                        type: 'warning'
                    });
                }
            });
        },//加入社区成员
    },
    data() {
        return {
            activeIndex: '5',//标题栏高显位置
            trendsActiveName: 'first',//
            critiqueDialog: false,//评论
            trendsDialog: false,//查看全部
            communityTrendsDialog: false,//社区动态
            communityInformationDialog: false,//查看社区
            textarea:'',
            //动态
            trends: [],
            collectTrends: [],//收藏动态
            saveTrends: [],//保存动态
            //查看全部动态
            hTrend: {},
            hCommunity: {},//查看社区
            //动态评论
            critiques: [],
            //当前评论
            critique: {
                content: '',
                time: date.toLocaleDateString()+'/'+date.toLocaleTimeString(),
                trendsId: ''
            },
            //个人社区
            myCommunities: [],
            memberCommunities: [],//关注社区
            community: {
                id:'',
                account:'',//创建者名称
                name:'',//社区名称
                numberFollowers:''//关注人数
            },
            communityTrends: [],//社区动态
        }
    }
}
const app = Vue.createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(ElementPlus);
app.mount("#app");